package until;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import module.ExtendTestSuite.TestResult;



public class Reporter {
	public String logFile;
	public Reporter () {
		
	}
	public  Reporter(String _logFile){
		logFile=_logFile;
		
	}
public void addReport(String _funtioName,String _testCase,String _testIssue,String _note,TestResult _testStatus){
	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	Calendar cal = Calendar.getInstance();
	String reportSummary = "</br><b>TEST REPORT - " + dateFormat.format(cal.getTime()) + "</b></br>";
	String tmpLog="</br></br><hr>";
	
	tmpLog += "<center><table style='border:1px solid black;' width='90%'>";
	tmpLog+="<tr>"
			+ "<th width='15%'>Funtion Name</th>"
			+ "<th width='20%'>Case Name</th>"
			+ "<th width='20%'>Role</th>"
			+ "<th width='35%'>Note</th>"
			+ "<th width='10%'>Status</th></tr>";
	           tmpLog +=reportSummary;
	if(_testStatus == TestResult.Pass){
		tmpLog +="<tr bgcolor='#33FF66'>";
		}
	else if(_testStatus==TestResult.Fail) {
		tmpLog +="<tr bgcolor='#B22222'>";
		
	}
	else if(_testStatus==TestResult.Note){
		tmpLog +="<tr bgcolor='#FFFFFF'>";
		
	}
	else if(_testStatus==TestResult.Warning){
		tmpLog +="<tr bgcolor='#CFC172'>";
		
	}
	

	
	tmpLog += "<td width='15%'>" + _funtioName + "</td>";
	tmpLog += "<td width='20%'>" + _testCase + "</td>";
	tmpLog += "<td width='20%'>" + _testIssue + "</td>";
	tmpLog +="<td width='45%'>" + _note + "</td>";
	tmpLog += "<td width='10%'>" + _testStatus.toString().toUpperCase() + "</td>";
	tmpLog += "</tr></table></center>";
	try {
		writeFile(logFile, tmpLog);
	} catch (FileNotFoundException e) {
		// TODO: handle exception
	e.printStackTrace();
	}
}
public void writeFile(String file,String Content) throws FileNotFoundException{
	PrintStream out=null;
	try{
		out=new PrintStream(new FileOutputStream(file,true));
		out.print(Content);
	}
	finally{
		if(out!=null) out.close(); 
	}
	
}

public void initLogFile () {
	
	
	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	Calendar cal = Calendar.getInstance();
	String reportSummary = "</br><b>TEST REPORT - " + dateFormat.format(cal.getTime()) + "</b></br>";
	//reportSummary += "Test profile: " + Tester.testProfile.file;
	reportSummary += "</br>Total case: xxx " + "     Fail: xxx " + "     Pass: xxx </br></br>";
	
	String initLog = "</br></br><hr>";
	initLog += "<center><table style='border:1px solid black;' width='90%'><tr>";
	initLog += reportSummary + "</tr><tr>";
	initLog += "<td width='15%' align='center'>Function</td>";
	initLog += "<td width='20%' align='center'>Testcase</td>";
	initLog += "<td width='45%' align='center'>Problem</td>";
	initLog += "<td width='10%' align='center'>Result</td>";
	initLog += "</tr></table></center></br>";
	
	try {
		writeFile(logFile, initLog);
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
}
}
